OS X开发:NSTextField文本输入框
NSTextField组件可以接收用户的输入,和UITextField不同,其可以将用户的输入进行多行显示。示例代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| - (void)viewDidLoad { [super viewDidLoad]; MyTextField * textField = [[MyTextField alloc]initWithFrame:NSMakeRect(100, 200, 300, 40)]; textField.placeholderString = @"默认文字"; textField.backgroundColor = [NSColor redColor]; textField.drawsBackground = YES; textField.textColor = [NSColor blueColor]; textField.bordered = YES; textField.bezeled = YES; textField.delegate = self; [self.view addSubview:textField]; }
|
NSTextField类解析如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| @property (nullable, copy) NSString *placeholderString;
@property (nullable, copy) NSAttributedString *placeholderAttributedString;
@property (nullable, copy) NSColor *backgroundColor;
@property BOOL drawsBackground;
@property (nullable, copy) NSColor *textColor;
@property (getter=isBordered) BOOL bordered;
@property (getter=isBezeled) BOOL bezeled;
@property (getter=isEditable) BOOL editable;
@property (getter=isSelectable) BOOL selectable;
- (void)selectText:(nullable id)sender;
@property (nullable, assign) id<NSTextFieldDelegate> delegate;
@property (readonly) BOOL acceptsFirstResponder;
@property NSTextFieldBezelStyle bezelStyle;
- (BOOL)textShouldBeginEditing:(NSText *)textObject;
- (BOOL)textShouldEndEditing:(NSText *)textObject;
- (void)textDidBeginEditing:(NSNotification *)notification;
- (void)textDidEndEditing:(NSNotification *)notification;
- (void)textDidChange:(NSNotification *)notification;
+ (instancetype)labelWithString:(NSString *)stringValue; + (instancetype)wrappingLabelWithString:(NSString *)stringValue; + (instancetype)textFieldWithString:(nullable NSString *)stringValue; + (instancetype)labelWithAttributedString:(NSAttributedString *)attributedStringValue;
|